OOP calling convention for database functions. DBMS abstraction implemented by means...
[lhc/web/wiklou.git] / includes / Article.php
1 <?php
2 # $Id$
3 #
4 # Class representing a Wikipedia article and history.
5 # See design.doc for an overview.
6
7 # Note: edit user interface and cache support functions have been
8 # moved to separate EditPage and CacheManager classes.
9
10 require_once( 'CacheManager.php' );
11
12 $wgArticleCurContentFields = false;
13 $wgArticleOldContentFields = false;
14
15 class Article {
16 /* private */ var $mContent, $mContentLoaded;
17 /* private */ var $mUser, $mTimestamp, $mUserText;
18 /* private */ var $mCounter, $mComment, $mCountAdjustment;
19 /* private */ var $mMinorEdit, $mRedirectedFrom;
20 /* private */ var $mTouched, $mFileCache, $mTitle;
21 /* private */ var $mId, $mTable;
22
23 function Article( &$title ) {
24 $this->mTitle =& $title;
25 $this->clear();
26 }
27
28 /* private */ function clear()
29 {
30 $this->mContentLoaded = false;
31 $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
32 $this->mRedirectedFrom = $this->mUserText =
33 $this->mTimestamp = $this->mComment = $this->mFileCache = '';
34 $this->mCountAdjustment = 0;
35 $this->mTouched = '19700101000000';
36 }
37
38 # Get revision text associated with an old or archive row
39 # $row is usually an object from wfFetchRow(), both the flags and the text field must be included
40 /* static */ function getRevisionText( $row, $prefix = 'old_' ) {
41 # Get data
42 $textField = $prefix . 'text';
43 $flagsField = $prefix . 'flags';
44
45 if ( isset( $row->$flagsField ) ) {
46 $flags = explode( ",", $row->$flagsField );
47 } else {
48 $flags = array();
49 }
50
51 if ( isset( $row->$textField ) ) {
52 $text = $row->$textField;
53 } else {
54 return false;
55 }
56
57 if ( in_array( 'link', $flags ) ) {
58 # Handle link type
59 $text = Article::followLink( $text );
60 } elseif ( in_array( 'gzip', $flags ) ) {
61 # Deal with optional compression of archived pages.
62 # This can be done periodically via maintenance/compressOld.php, and
63 # as pages are saved if $wgCompressRevisions is set.
64 return gzinflate( $text );
65 }
66 return $text;
67 }
68
69 /* static */ function compressRevisionText( &$text ) {
70 global $wgCompressRevisions;
71 if( !$wgCompressRevisions ) {
72 return '';
73 }
74 if( !function_exists( 'gzdeflate' ) ) {
75 wfDebug( "Article::compressRevisionText() -- no zlib support, not compressing\n" );
76 return '';
77 }
78 $text = gzdeflate( $text );
79 return 'gzip';
80 }
81
82 # Returns the text associated with a "link" type old table row
83 /* static */ function followLink( $link ) {
84 # Split the link into fields and values
85 $lines = explode( '\n', $link );
86 $hash = '';
87 $locations = array();
88 foreach ( $lines as $line ) {
89 # Comments
90 if ( $line{0} == '#' ) {
91 continue;
92 }
93 # Field/value pairs
94 if ( preg_match( '/^(.*?)\s*:\s*(.*)$/', $line, $matches ) ) {
95 $field = strtolower($matches[1]);
96 $value = $matches[2];
97 if ( $field == 'hash' ) {
98 $hash = $value;
99 } elseif ( $field == 'location' ) {
100 $locations[] = $value;
101 }
102 }
103 }
104
105 if ( $hash === '' ) {
106 return false;
107 }
108
109 # Look in each specified location for the text
110 $text = false;
111 foreach ( $locations as $location ) {
112 $text = Article::fetchFromLocation( $location, $hash );
113 if ( $text !== false ) {
114 break;
115 }
116 }
117
118 return $text;
119 }
120
121 /* static */ function fetchFromLocation( $location, $hash ) {
122 global $wgLoadBalancer;
123 $fname = 'fetchFromLocation';
124 wfProfileIn( $fname );
125
126 $p = strpos( $location, ':' );
127 if ( $p === false ) {
128 wfProfileOut( $fname );
129 return false;
130 }
131
132 $type = substr( $location, 0, $p );
133 $text = false;
134 switch ( $type ) {
135 case 'mysql':
136 # MySQL locations are specified by mysql://<machineID>/<dbname>/<tblname>/<index>
137 # Machine ID 0 is the current connection
138 if ( preg_match( '/^mysql:\/\/(\d+)\/([A-Za-z_]+)\/([A-Za-z_]+)\/([A-Za-z_]+)$/',
139 $location, $matches ) ) {
140 $machineID = $matches[1];
141 $dbName = $matches[2];
142 $tblName = $matches[3];
143 $index = $matches[4];
144 if ( $machineID == 0 ) {
145 # Current connection
146 $db =& wfGetDB( DB_READ );
147 } else {
148 # Alternate connection
149 $db =& $wgLoadBalancer->getConnection( $machineID );
150
151 if ( array_key_exists( $machineId, $wgKnownMysqlServers ) ) {
152 # Try to open, return false on failure
153 $params = $wgKnownDBServers[$machineId];
154 $db = Database::newFromParams( $params['server'], $params['user'], $params['password'],
155 $dbName, 1, false, true, true );
156 }
157 }
158 if ( $db->isOpen() ) {
159 $index = $db->strencode( $index );
160 $res = $db->query( "SELECT blob_data FROM $dbName.$tblName WHERE blob_index='$index'", $fname );
161 $row = $db->fetchObject( $res );
162 $text = $row->text_data;
163 }
164 }
165 break;
166 case 'file':
167 # File locations are of the form file://<filename>, relative to the current directory
168 if ( preg_match( '/^file:\/\/(.*)$', $location, $matches ) )
169 $filename = strstr( $location, 'file://' );
170 $text = @file_get_contents( $matches[1] );
171 }
172 if ( $text !== false ) {
173 # Got text, now we need to interpret it
174 # The first line contains information about how to do this
175 $p = strpos( $text, '\n' );
176 $type = substr( $text, 0, $p );
177 $text = substr( $text, $p + 1 );
178 switch ( $type ) {
179 case 'plain':
180 break;
181 case 'gzip':
182 $text = gzinflate( $text );
183 break;
184 case 'object':
185 $object = unserialize( $text );
186 $text = $object->getItem( $hash );
187 break;
188 default:
189 $text = false;
190 }
191 }
192 wfProfileOut( $fname );
193 return $text;
194 }
195
196 # Note that getContent/loadContent may follow redirects if
197 # not told otherwise, and so may cause a change to mTitle.
198
199 # Return the text of this revision
200 function getContent( $noredir )
201 {
202 global $wgRequest;
203
204 # Get variables from query string :P
205 $action = $wgRequest->getText( 'action', 'view' );
206 $section = $wgRequest->getText( 'section' );
207
208 $fname = 'Article::getContent';
209 wfProfileIn( $fname );
210
211 if ( 0 == $this->getID() ) {
212 if ( 'edit' == $action ) {
213 wfProfileOut( $fname );
214 return ''; # was "newarticletext", now moved above the box)
215 }
216 wfProfileOut( $fname );
217 return wfMsg( 'noarticletext' );
218 } else {
219 $this->loadContent( $noredir );
220
221 if(
222 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
223 ( $this->mTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
224 preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle->getText()) &&
225 $action=='view'
226 )
227 {
228 wfProfileOut( $fname );
229 return $this->mContent . "\n" .wfMsg('anontalkpagetext'); }
230 else {
231 if($action=='edit') {
232 if($section!='') {
233 if($section=='new') {
234 wfProfileOut( $fname );
235 return '';
236 }
237
238 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
239 # comments to be stripped as well)
240 $rv=$this->getSection($this->mContent,$section);
241 wfProfileOut( $fname );
242 return $rv;
243 }
244 }
245 wfProfileOut( $fname );
246 return $this->mContent;
247 }
248 }
249 }
250
251 # This function returns the text of a section, specified by a number ($section).
252 # A section is text under a heading like == Heading == or <h1>Heading</h1>, or
253 # the first section before any such heading (section 0).
254 #
255 # If a section contains subsections, these are also returned.
256 #
257 function getSection($text,$section) {
258
259 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
260 # comments to be stripped as well)
261 $striparray=array();
262 $parser=new Parser();
263 $parser->mOutputType=OT_WIKI;
264 $striptext=$parser->strip($text, $striparray, true);
265
266 # now that we can be sure that no pseudo-sections are in the source,
267 # split it up by section
268 $secs =
269 preg_split(
270 '/(^=+.*?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)/mi',
271 $striptext, -1,
272 PREG_SPLIT_DELIM_CAPTURE);
273 if($section==0) {
274 $rv=$secs[0];
275 } else {
276 $headline=$secs[$section*2-1];
277 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$headline,$matches);
278 $hlevel=$matches[1];
279
280 # translate wiki heading into level
281 if(strpos($hlevel,'=')!==false) {
282 $hlevel=strlen($hlevel);
283 }
284
285 $rv=$headline. $secs[$section*2];
286 $count=$section+1;
287
288 $break=false;
289 while(!empty($secs[$count*2-1]) && !$break) {
290
291 $subheadline=$secs[$count*2-1];
292 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$subheadline,$matches);
293 $subhlevel=$matches[1];
294 if(strpos($subhlevel,'=')!==false) {
295 $subhlevel=strlen($subhlevel);
296 }
297 if($subhlevel > $hlevel) {
298 $rv.=$subheadline.$secs[$count*2];
299 }
300 if($subhlevel <= $hlevel) {
301 $break=true;
302 }
303 $count++;
304
305 }
306 }
307 # reinsert stripped tags
308 $rv=$parser->unstrip($rv,$striparray);
309 $rv=$parser->unstripNoWiki($rv,$striparray);
310 $rv=trim($rv);
311 return $rv;
312
313 }
314
315 function &getCurContentFields() {
316 global $wgArticleCurContentFields;
317 if ( !$wgArticleCurContentFields ) {
318 $wgArticleCurContentFields = array( 'cur_text','cur_timestamp','cur_user', 'cur_user_text',
319 'cur_comment','cur_counter','cur_restrictions','cur_touched' );
320 }
321 return $wgArticleCurContentFields;
322 }
323
324 function &getOldContentFields() {
325 global $wgArticleOldContentFields;
326 if ( !$wgArticleOldContentFields ) {
327 $wgArticleOldContentFields = array( 'old_namespace','old_title','old_text','old_timestamp',
328 'old_user','old_user_text','old_comment','old_flags' );
329 }
330 return $wgArticleOldContentFields;
331 }
332
333 # Load the revision (including cur_text) into this object
334 function loadContent( $noredir = false )
335 {
336 global $wgOut, $wgMwRedir, $wgRequest;
337
338 $dbr =& wfGetDB( DB_READ );
339 # Query variables :P
340 $oldid = $wgRequest->getVal( 'oldid' );
341 $redirect = $wgRequest->getVal( 'redirect' );
342
343 if ( $this->mContentLoaded ) return;
344 $fname = 'Article::loadContent';
345
346 # Pre-fill content with error message so that if something
347 # fails we'll have something telling us what we intended.
348
349 $t = $this->mTitle->getPrefixedText();
350 if ( isset( $oldid ) ) {
351 $oldid = IntVal( $oldid );
352 $t .= ",oldid={$oldid}";
353 }
354 if ( isset( $redirect ) ) {
355 $redirect = ($redirect == 'no') ? 'no' : 'yes';
356 $t .= ",redirect={$redirect}";
357 }
358 $this->mContent = wfMsg( 'missingarticle', $t );
359
360 if ( ! $oldid ) { # Retrieve current version
361 $id = $this->getID();
362 if ( 0 == $id ) return;
363
364 $s = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ), $fname );
365 if ( $s === false ) {
366 return;
367 }
368
369 # If we got a redirect, follow it (unless we've been told
370 # not to by either the function parameter or the query
371 if ( ( 'no' != $redirect ) && ( false == $noredir ) &&
372 ( $wgMwRedir->matchStart( $s->cur_text ) ) ) {
373 if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/',
374 $s->cur_text, $m ) ) {
375 $rt = Title::newFromText( $m[1] );
376 if( $rt ) {
377 # Gotta hand redirects to special pages differently:
378 # Fill the HTTP response "Location" header and ignore
379 # the rest of the page we're on.
380
381 if ( $rt->getInterwiki() != '' ) {
382 $wgOut->redirect( $rt->getFullURL() ) ;
383 return;
384 }
385 if ( $rt->getNamespace() == Namespace::getSpecial() ) {
386 $wgOut->redirect( $rt->getFullURL() );
387 return;
388 }
389 $rid = $rt->getArticleID();
390 if ( 0 != $rid ) {
391 $redirRow = $dbr->getArray( 'cur', $this->getContentFields(), array( 'cur_id' => $rid ), $fname );
392
393 if ( $redirRow !== false ) {
394 $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
395 $this->mTitle = $rt;
396 $s = $redirRow;
397 }
398 }
399 }
400 }
401 }
402
403 $this->mContent = $s->cur_text;
404 $this->mUser = $s->cur_user;
405 $this->mUserText = $s->cur_user_text;
406 $this->mComment = $s->cur_comment;
407 $this->mCounter = $s->cur_counter;
408 $this->mTimestamp = $s->cur_timestamp;
409 $this->mTouched = $s->cur_touched;
410 $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
411 $this->mTitle->mRestrictionsLoaded = true;
412 } else { # oldid set, retrieve historical version
413 $s = $dbr->getArray( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ), $fname );
414 if ( $s === false ) {
415 return;
416 }
417
418 if( $this->mTitle->getNamespace() != $s->old_namespace ||
419 $this->mTitle->getDBkey() != $s->old_title ) {
420 $oldTitle = Title::makeTitle( $s->old_namesapce, $s->old_title );
421 $this->mTitle = $oldTitle;
422 $wgTitle = $oldTitle;
423 }
424 $this->mContent = Article::getRevisionText( $s );
425 $this->mUser = $s->old_user;
426 $this->mUserText = $s->old_user_text;
427 $this->mComment = $s->old_comment;
428 $this->mCounter = 0;
429 $this->mTimestamp = $s->old_timestamp;
430 }
431 $this->mContentLoaded = true;
432 return $this->mContent;
433 }
434
435 # Gets the article text without using so many damn globals
436 # Returns false on error
437 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
438 global $wgMwRedir;
439
440 if ( $this->mContentLoaded ) {
441 return $this->mContent;
442 }
443 $this->mContent = false;
444
445 $fname = 'Article::getContentWithout';
446 $dbr =& wfGetDB( DB_READ );
447
448 if ( ! $oldid ) { # Retrieve current version
449 $id = $this->getID();
450 if ( 0 == $id ) {
451 return false;
452 }
453
454 $s = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ), $fname );
455 if ( $s === false ) {
456 return false;
457 }
458
459 # If we got a redirect, follow it (unless we've been told
460 # not to by either the function parameter or the query
461 if ( !$noredir && $wgMwRedir->matchStart( $s->cur_text ) ) {
462 if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/',
463 $s->cur_text, $m ) ) {
464 $rt = Title::newFromText( $m[1] );
465 if( $rt && $rt->getInterwiki() == '' && $rt->getNamespace() != Namespace::getSpecial() ) {
466 $rid = $rt->getArticleID();
467 if ( 0 != $rid ) {
468 $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
469
470 if ( $redirRow !== false ) {
471 $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
472 $this->mTitle = $rt;
473 $s = $redirRow;
474 }
475 }
476 }
477 }
478 }
479
480 $this->mContent = $s->cur_text;
481 $this->mUser = $s->cur_user;
482 $this->mUserText = $s->cur_user_text;
483 $this->mComment = $s->cur_comment;
484 $this->mCounter = $s->cur_counter;
485 $this->mTimestamp = $s->cur_timestamp;
486 $this->mTouched = $s->cur_touched;
487 $this->mTitle->mRestrictions = explode( ",", trim( $s->cur_restrictions ) );
488 $this->mTitle->mRestrictionsLoaded = true;
489 } else { # oldid set, retrieve historical version
490 $s = $dbr->getArray( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ) );
491 if ( $s === false ) {
492 return false;
493 }
494 $this->mContent = Article::getRevisionText( $s );
495 $this->mUser = $s->old_user;
496 $this->mUserText = $s->old_user_text;
497 $this->mComment = $s->old_comment;
498 $this->mCounter = 0;
499 $this->mTimestamp = $s->old_timestamp;
500 }
501 $this->mContentLoaded = true;
502 return $this->mContent;
503 }
504
505 function getID() {
506 if( $this->mTitle ) {
507 return $this->mTitle->getArticleID();
508 } else {
509 return 0;
510 }
511 }
512
513 function getCount()
514 {
515 if ( -1 == $this->mCounter ) {
516 $id = $this->getID();
517 $dbr =& wfGetDB( DB_READ );
518 $this->mCounter = $dbr->getField( 'cur', 'cur_counter', "cur_id={$id}" );
519 }
520 return $this->mCounter;
521 }
522
523 # Would the given text make this article a "good" article (i.e.,
524 # suitable for including in the article count)?
525
526 function isCountable( $text )
527 {
528 global $wgUseCommaCount, $wgMwRedir;
529
530 if ( 0 != $this->mTitle->getNamespace() ) { return 0; }
531 if ( $wgMwRedir->matchStart( $text ) ) { return 0; }
532 $token = ($wgUseCommaCount ? ',' : '[[' );
533 if ( false === strstr( $text, $token ) ) { return 0; }
534 return 1;
535 }
536
537 # Loads everything from cur except cur_text
538 # This isn't necessary for all uses, so it's only done if needed.
539
540 /* private */ function loadLastEdit()
541 {
542 global $wgOut;
543 if ( -1 != $this->mUser ) return;
544
545 $fname = 'Article::loadLastEdit';
546
547 $dbr =& wfGetDB( DB_READ );
548 $s = $dbr->getArray( 'cur',
549 array( 'cur_user','cur_user_text','cur_timestamp', 'cur_comment','cur_minor_edit' ),
550 array( 'cur_id' => $this->getID() ), $fname );
551
552 if ( $s !== false ) {
553 $this->mUser = $s->cur_user;
554 $this->mUserText = $s->cur_user_text;
555 $this->mTimestamp = $s->cur_timestamp;
556 $this->mComment = $s->cur_comment;
557 $this->mMinorEdit = $s->cur_minor_edit;
558 }
559 }
560
561 function getTimestamp()
562 {
563 $this->loadLastEdit();
564 return $this->mTimestamp;
565 }
566
567 function getUser()
568 {
569 $this->loadLastEdit();
570 return $this->mUser;
571 }
572
573 function getUserText()
574 {
575 $this->loadLastEdit();
576 return $this->mUserText;
577 }
578
579 function getComment()
580 {
581 $this->loadLastEdit();
582 return $this->mComment;
583 }
584
585 function getMinorEdit()
586 {
587 $this->loadLastEdit();
588 return $this->mMinorEdit;
589 }
590
591 function getContributors($limit = 0, $offset = 0)
592 {
593 $fname = 'Article::getContributors';
594
595 # XXX: this is expensive; cache this info somewhere.
596
597 $title = $this->mTitle;
598 $contribs = array();
599 $dbr = wfGetDB( DB_READ );
600 $oldTable = $dbr->tableName( 'old' );
601 $userTable = $dbr->tableName( 'user' );
602 $encDBkey = $dbr->strencode( $title->getDBkey() );
603 $ns = $title->getNamespace();
604 $user = $this->getUser();
605
606 $sql = "SELECT old_user, old_user_text, user_real_name, MAX(old_timestamp) as timestamp
607 FROM $oldTable LEFT JOIN $userTable ON old_user = user_id
608 WHERE old_namespace = $user
609 AND old_title = $encDBkey
610 AND old_user != $user
611 GROUP BY old_user
612 ORDER BY timestamp DESC";
613
614 if ($limit > 0) {
615 $sql .= ' LIMIT '.$limit;
616 }
617
618 $res = $dbr->query($sql, $fname);
619
620 while ( $line = $dbr->fetchObject( $res ) ) {
621 $contribs[] = array($line->old_user, $line->old_user_text, $line->user_real_name);
622 }
623
624 $dbr->freeResult($res);
625
626 return $contribs;
627 }
628
629 # This is the default action of the script: just view the page of
630 # the given title.
631
632 function view()
633 {
634 global $wgUser, $wgOut, $wgLang, $wgRequest;
635 global $wgLinkCache, $IP, $wgEnableParserCache;
636
637 $fname = 'Article::view';
638 wfProfileIn( $fname );
639
640 # Get variables from query string :P
641 $oldid = $wgRequest->getVal( 'oldid' );
642 $diff = $wgRequest->getVal( 'diff' );
643
644 $wgOut->setArticleFlag( true );
645 $wgOut->setRobotpolicy( 'index,follow' );
646
647 # If we got diff and oldid in the query, we want to see a
648 # diff page instead of the article.
649
650 if ( !is_null( $diff ) ) {
651 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
652 $de = new DifferenceEngine( intval($oldid), intval($diff) );
653 $de->showDiffPage();
654 wfProfileOut( $fname );
655 return;
656 }
657
658 if ( !is_null( $oldid ) and $this->checkTouched() ) {
659 if( $wgOut->checkLastModified( $this->mTouched ) ){
660 return;
661 } else if ( $this->tryFileCache() ) {
662 # tell wgOut that output is taken care of
663 $wgOut->disable();
664 $this->viewUpdates();
665 return;
666 }
667 }
668
669 # Should the parser cache be used?
670 if ( $wgEnableParserCache && intval($wgUser->getOption( 'stubthreshold' )) == 0 && empty( $oldid ) ) {
671 $pcache = true;
672 } else {
673 $pcache = false;
674 }
675
676 $outputDone = false;
677 if ( $pcache ) {
678 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
679 $outputDone = true;
680 }
681 }
682
683 if ( !$outputDone ) {
684 $text = $this->getContent( false ); # May change mTitle by following a redirect
685
686 # Another whitelist check in case oldid or redirects are altering the title
687 if ( !$this->mTitle->userCanRead() ) {
688 $wgOut->loginToUse();
689 $wgOut->output();
690 exit;
691 }
692
693
694 # We're looking at an old revision
695
696 if ( !empty( $oldid ) ) {
697 $this->setOldSubtitle();
698 $wgOut->setRobotpolicy( 'noindex,follow' );
699 }
700 if ( '' != $this->mRedirectedFrom ) {
701 $sk = $wgUser->getSkin();
702 $redir = $sk->makeKnownLink( $this->mRedirectedFrom, '',
703 'redirect=no' );
704 $s = wfMsg( 'redirectedfrom', $redir );
705 $wgOut->setSubtitle( $s );
706
707 # Can't cache redirects
708 $pcache = false;
709 }
710
711 $wgLinkCache->preFill( $this->mTitle );
712
713 # wrap user css and user js in pre and don't parse
714 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
715 if (
716 $this->mTitle->getNamespace() == Namespace::getUser() &&
717 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey())
718 ) {
719 $wgOut->addWikiText( wfMsg('clearyourcache'));
720 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
721 } else if ( $pcache ) {
722 $wgOut->addWikiText( $text, true, $this );
723 } else {
724 $wgOut->addWikiText( $text );
725 }
726 }
727 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
728
729 # Add link titles as META keywords
730 $wgOut->addMetaTags() ;
731
732 $this->viewUpdates();
733 wfProfileOut( $fname );
734 }
735
736 # Theoretically we could defer these whole insert and update
737 # functions for after display, but that's taking a big leap
738 # of faith, and we want to be able to report database
739 # errors at some point.
740
741 /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis )
742 {
743 global $wgOut, $wgUser, $wgLinkCache, $wgMwRedir;
744 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
745
746 $fname = 'Article::insertNewArticle';
747
748 $this->mCountAdjustment = $this->isCountable( $text );
749
750 $ns = $this->mTitle->getNamespace();
751 $ttl = $this->mTitle->getDBkey();
752 $text = $this->preSaveTransform( $text );
753 if ( $wgMwRedir->matchStart( $text ) ) { $redir = 1; }
754 else { $redir = 0; }
755
756 $now = wfTimestampNow();
757 $won = wfInvertTimestamp( $now );
758 wfSeedRandom();
759 $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
760 $dbw =& wfGetDB( DB_WRITE );
761
762 $cur_id = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
763
764 $isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0;
765
766 $dbw->insertArray( 'cur', array(
767 'cur_id' => $cur_id,
768 'cur_namespace' => $ns,
769 'cur_title' => $ttl,
770 'cur_text' => $text,
771 'cur_comment' => $summary,
772 'cur_user' => $wgUser->getID(),
773 'cur_timestamp' => $now,
774 'cur_minor_edit' => $isminor,
775 'cur_counter' => 0,
776 'cur_restrictions' => '',
777 'cur_user_text' => $wgUser->getName(),
778 'cur_is_redirect' => $redir,
779 'cur_is_new' => 1,
780 'cur_random' => $rand,
781 'cur_touched' => $now,
782 'inverse_timestamp' => $won,
783 ), $fname );
784
785 $newid = $dbw->insertId();
786 $this->mTitle->resetArticleID( $newid );
787
788 Article::onArticleCreate( $this->mTitle );
789 RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
790
791 if ($watchthis) {
792 if(!$this->mTitle->userIsWatching()) $this->watch();
793 } else {
794 if ( $this->mTitle->userIsWatching() ) {
795 $this->unwatch();
796 }
797 }
798
799 # The talk page isn't in the regular link tables, so we need to update manually:
800 $talkns = $ns ^ 1; # talk -> normal; normal -> talk
801 $dbw->updateArray( 'cur', array( 'cur_touched' => $now ), array( 'cur_namespace' => $talkns, 'cur_title' => $ttl ), $fname );
802
803 # standard deferred updates
804 $this->editUpdates( $text );
805
806 $this->showArticle( $text, wfMsg( 'newarticle' ) );
807 }
808
809
810 /* Side effects: loads last edit */
811 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = ''){
812 $this->loadLastEdit();
813 $oldtext = $this->getContent( true );
814 if ($section != '') {
815 if($section=='new') {
816 if($summary) $subject="== {$summary} ==\n\n";
817 $text=$oldtext."\n\n".$subject.$text;
818 } else {
819
820 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
821 # comments to be stripped as well)
822 $striparray=array();
823 $parser=new Parser();
824 $parser->mOutputType=OT_WIKI;
825 $oldtext=$parser->strip($oldtext, $striparray, true);
826
827 # now that we can be sure that no pseudo-sections are in the source,
828 # split it up
829 # Unfortunately we can't simply do a preg_replace because that might
830 # replace the wrong section, so we have to use the section counter instead
831 $secs=preg_split('/(^=+.*?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)/mi',
832 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
833 $secs[$section*2]=$text."\n\n"; // replace with edited
834
835 # section 0 is top (intro) section
836 if($section!=0) {
837
838 # headline of old section - we need to go through this section
839 # to determine if there are any subsections that now need to
840 # be erased, as the mother section has been replaced with
841 # the text of all subsections.
842 $headline=$secs[$section*2-1];
843 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$headline,$matches);
844 $hlevel=$matches[1];
845
846 # determine headline level for wikimarkup headings
847 if(strpos($hlevel,'=')!==false) {
848 $hlevel=strlen($hlevel);
849 }
850
851 $secs[$section*2-1]=''; // erase old headline
852 $count=$section+1;
853 $break=false;
854 while(!empty($secs[$count*2-1]) && !$break) {
855
856 $subheadline=$secs[$count*2-1];
857 preg_match(
858 '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$subheadline,$matches);
859 $subhlevel=$matches[1];
860 if(strpos($subhlevel,'=')!==false) {
861 $subhlevel=strlen($subhlevel);
862 }
863 if($subhlevel > $hlevel) {
864 // erase old subsections
865 $secs[$count*2-1]='';
866 $secs[$count*2]='';
867 }
868 if($subhlevel <= $hlevel) {
869 $break=true;
870 }
871 $count++;
872
873 }
874
875 }
876 $text=join('',$secs);
877 # reinsert the stuff that we stripped out earlier
878 $text=$parser->unstrip($text,$striparray);
879 $text=$parser->unstripNoWiki($text,$striparray);
880 }
881
882 }
883 return $text;
884 }
885
886 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' )
887 {
888 global $wgOut, $wgUser, $wgLinkCache;
889 global $wgDBtransactions, $wgMwRedir;
890 global $wgUseSquid, $wgInternalServer;
891
892 $fname = 'Article::updateArticle';
893 $good = true;
894
895 if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
896 if ( $minor && $wgUser->getID() ) { $me2 = 1; } else { $me2 = 0; }
897 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
898 $redir = 1;
899 $text = $m[1] . "\n"; # Remove all content but redirect
900 }
901 else { $redir = 0; }
902
903 $text = $this->preSaveTransform( $text );
904 $dbw =& wfGetDB( DB_WRITE );
905
906 # Update article, but only if changed.
907
908 # It's important that we either rollback or complete, otherwise an attacker could
909 # overwrite cur entries by sending precisely timed user aborts. Random bored users
910 # could conceivably have the same effect, especially if cur is locked for long periods.
911 if( $wgDBtransactions ) {
912 $dbw->query( 'BEGIN', $fname );
913 } else {
914 $userAbort = ignore_user_abort( true );
915 }
916
917 $oldtext = $this->getContent( true );
918
919 if ( 0 != strcmp( $text, $oldtext ) ) {
920 $this->mCountAdjustment = $this->isCountable( $text )
921 - $this->isCountable( $oldtext );
922 $now = wfTimestampNow();
923 $won = wfInvertTimestamp( $now );
924
925 # First update the cur row
926 $dbw->updateArray( 'cur',
927 array( /* SET */
928 'cur_text' => $text,
929 'cur_comment' => $summary,
930 'cur_minor_edit' => $me2,
931 'cur_user' => $wgUser->getID(),
932 'cur_timestamp' => $now,
933 'cur_user_text' => $wgUser->getName(),
934 'cur_is_redirect' => $redir,
935 'cur_is_new' => 0,
936 'cur_touched' => $now,
937 'inverse_timestamp' => $won
938 ), array( /* WHERE */
939 'cur_id' => $this->getID(),
940 'cur_timestamp' => $this->getTimestamp()
941 ), $fname
942 );
943
944 if( $dbw->affectedRows() == 0 ) {
945 /* Belated edit conflict! Run away!! */
946 $good = false;
947 } else {
948 # Now insert the previous revision into old
949
950 # This overwrites $oldtext if revision compression is on
951 $flags = Article::compressRevisionText( $oldtext );
952
953 $dbw->insertArray( 'old',
954 array(
955 'old_id' => $dbw->nextSequenceValue( 'old_old_id_seq' ),
956 'old_namespace' => $this->mTitle->getNamespace(),
957 'old_title' => $this->mTitle->getDBkey(),
958 'old_text' => $oldtext,
959 'old_comment' => $this->getComment(),
960 'old_user' => $this->getUser(),
961 'old_user_text' => $this->getUserText(),
962 'old_timestamp' => $this->getTimestamp(),
963 'old_minor_edit' => $me1,
964 'inverse_timestamp' => wfInvertTimestamp( $this->getTimestamp() ),
965 'old_flags' => $flags,
966 ), $fname
967 );
968
969 $oldid = $dbw->insertId();
970
971 $bot = (int)($wgUser->isBot() || $forceBot);
972 RecentChange::notifyEdit( $now, $this->mTitle, $me2, $wgUser, $summary,
973 $oldid, $this->getTimestamp(), $bot );
974 Article::onArticleEdit( $this->mTitle );
975 }
976 }
977
978 if( $wgDBtransactions ) {
979 $dbw->query( 'COMMIT', $fname );
980 } else {
981 ignore_user_abort( $userAbort );
982 }
983
984 if ( $good ) {
985 if ($watchthis) {
986 if (!$this->mTitle->userIsWatching()) $this->watch();
987 } else {
988 if ( $this->mTitle->userIsWatching() ) {
989 $this->unwatch();
990 }
991 }
992 # standard deferred updates
993 $this->editUpdates( $text );
994
995
996 $urls = array();
997 # Template namespace
998 # Purge all articles linking here
999 if ( $this->mTitle->getNamespace() == NS_TEMPLATE) {
1000 $titles = $this->mTitle->getLinksTo();
1001 Title::touchArray( $titles );
1002 if ( $wgUseSquid ) {
1003 foreach ( $titles as $title ) {
1004 $urls[] = $title->getInternalURL();
1005 }
1006 }
1007 }
1008
1009 # Squid updates
1010 if ( $wgUseSquid ) {
1011 $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
1012 $u = new SquidUpdate( $urls );
1013 $u->doUpdate();
1014 }
1015
1016 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor );
1017 }
1018 return $good;
1019 }
1020
1021 # After we've either updated or inserted the article, update
1022 # the link tables and redirect to the new page.
1023
1024 function showArticle( $text, $subtitle , $sectionanchor = '' )
1025 {
1026 global $wgOut, $wgUser, $wgLinkCache;
1027 global $wgMwRedir;
1028
1029 $wgLinkCache = new LinkCache();
1030
1031 # Get old version of link table to allow incremental link updates
1032 $wgLinkCache->preFill( $this->mTitle );
1033 $wgLinkCache->clear();
1034
1035 # Now update the link cache by parsing the text
1036 $wgOut = new OutputPage();
1037 $wgOut->addWikiText( $text );
1038
1039 if( $wgMwRedir->matchStart( $text ) )
1040 $r = 'redirect=no';
1041 else
1042 $r = '';
1043 $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
1044 }
1045
1046 # Add this page to my watchlist
1047
1048 function watch( $add = true )
1049 {
1050 global $wgUser, $wgOut, $wgLang;
1051 global $wgDeferredUpdateList;
1052
1053 if ( 0 == $wgUser->getID() ) {
1054 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1055 return;
1056 }
1057 if ( wfReadOnly() ) {
1058 $wgOut->readOnlyPage();
1059 return;
1060 }
1061 if( $add )
1062 $wgUser->addWatch( $this->mTitle );
1063 else
1064 $wgUser->removeWatch( $this->mTitle );
1065
1066 $wgOut->setPagetitle( wfMsg( $add ? 'addedwatch' : 'removedwatch' ) );
1067 $wgOut->setRobotpolicy( 'noindex,follow' );
1068
1069 $sk = $wgUser->getSkin() ;
1070 $link = $this->mTitle->getPrefixedText();
1071
1072 if($add)
1073 $text = wfMsg( 'addedwatchtext', $link );
1074 else
1075 $text = wfMsg( 'removedwatchtext', $link );
1076 $wgOut->addWikiText( $text );
1077
1078 $up = new UserUpdate();
1079 array_push( $wgDeferredUpdateList, $up );
1080
1081 $wgOut->returnToMain( false );
1082 }
1083
1084 function unwatch()
1085 {
1086 $this->watch( false );
1087 }
1088
1089 function protect( $limit = 'sysop' )
1090 {
1091 global $wgUser, $wgOut, $wgRequest;
1092
1093 if ( ! $wgUser->isSysop() ) {
1094 $wgOut->sysopRequired();
1095 return;
1096 }
1097 if ( wfReadOnly() ) {
1098 $wgOut->readOnlyPage();
1099 return;
1100 }
1101 $id = $this->mTitle->getArticleID();
1102 if ( 0 == $id ) {
1103 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1104 return;
1105 }
1106
1107 $confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
1108 $reason = $wgRequest->getText( 'wpReasonProtect' );
1109
1110 if ( $confirm ) {
1111 $dbw =& wfGetDB( DB_WRITE );
1112 $dbw->updateArray( 'cur',
1113 array( /* SET */
1114 'cur_touched' => wfTimestampNow(),
1115 'cur_restrictions' => (string)$limit
1116 ), array( /* WHERE */
1117 'cur_id' => $id
1118 ), 'Article::protect'
1119 );
1120
1121 $log = new LogPage( wfMsg( 'protectlogpage' ), wfMsg( 'protectlogtext' ) );
1122 if ( $limit === "" ) {
1123 $log->addEntry( wfMsg( 'unprotectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1124 } else {
1125 $log->addEntry( wfMsg( 'protectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1126 }
1127 $wgOut->redirect( $this->mTitle->getFullURL() );
1128 return;
1129 } else {
1130 $reason = htmlspecialchars( wfMsg( 'protectreason' ) );
1131 return $this->confirmProtect( '', $reason, $limit );
1132 }
1133 }
1134
1135 # Output protection confirmation dialog
1136 function confirmProtect( $par, $reason, $limit = 'sysop' )
1137 {
1138 global $wgOut;
1139
1140 wfDebug( "Article::confirmProtect\n" );
1141
1142 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1143 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1144
1145 $check = '';
1146 $protcom = '';
1147
1148 if ( $limit === '' ) {
1149 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1150 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1151 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1152 $check = htmlspecialchars( wfMsg( 'confirmunprotect' ) );
1153 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1154 $formaction = $this->mTitle->escapeLocalURL( 'action=unprotect' . $par );
1155 } else {
1156 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1157 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1158 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1159 $check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
1160 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1161 $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
1162 }
1163
1164 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1165
1166 $wgOut->addHTML( "
1167 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1168 <table border='0'>
1169 <tr>
1170 <td align='right'>
1171 <label for='wpReasonProtect'>{$protcom}:</label>
1172 </td>
1173 <td align='left'>
1174 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1175 </td>
1176 </tr>
1177 <tr>
1178 <td>&nbsp;</td>
1179 </tr>
1180 <tr>
1181 <td align='right'>
1182 <input type='checkbox' name='wpConfirmProtect' value='1' id='wpConfirmProtect' />
1183 </td>
1184 <td>
1185 <label for='wpConfirmProtect'>{$check}</label>
1186 </td>
1187 </tr>
1188 <tr>
1189 <td>&nbsp;</td>
1190 <td>
1191 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1192 </td>
1193 </tr>
1194 </table>
1195 </form>\n" );
1196
1197 $wgOut->returnToMain( false );
1198 }
1199
1200 function unprotect()
1201 {
1202 return $this->protect( '' );
1203 }
1204
1205 # UI entry point for page deletion
1206 function delete()
1207 {
1208 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1209 $fname = 'Article::delete';
1210 $confirm = $wgRequest->getBool( 'wpConfirm' ) && $wgRequest->wasPosted();
1211 $reason = $wgRequest->getText( 'wpReason' );
1212
1213 # This code desperately needs to be totally rewritten
1214
1215 # Check permissions
1216 if ( ( ! $wgUser->isSysop() ) ) {
1217 $wgOut->sysopRequired();
1218 return;
1219 }
1220 if ( wfReadOnly() ) {
1221 $wgOut->readOnlyPage();
1222 return;
1223 }
1224
1225 # Better double-check that it hasn't been deleted yet!
1226 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1227 if ( ( '' == trim( $this->mTitle->getText() ) )
1228 or ( $this->mTitle->getArticleId() == 0 ) ) {
1229 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1230 return;
1231 }
1232
1233 if ( $confirm ) {
1234 $this->doDelete( $reason );
1235 return;
1236 }
1237
1238 # determine whether this page has earlier revisions
1239 # and insert a warning if it does
1240 # we select the text because it might be useful below
1241 $dbr =& wfGetDB( DB_READ );
1242 $ns = $this->mTitle->getNamespace();
1243 $title = $this->mTitle->getDBkey();
1244 $old = $dbr->getArray( 'old',
1245 array( 'old_text', 'old_flags' ),
1246 array(
1247 'old_namespace' => $ns,
1248 'old_title' => $title,
1249 ), $fname, array( 'ORDER BY' => 'inverse_timestamp' )
1250 );
1251
1252 if( $old !== false && !$confirm ) {
1253 $skin=$wgUser->getSkin();
1254 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1255 $wgOut->addHTML( $skin->historyLink() .'</b>');
1256 }
1257
1258 # Fetch cur_text
1259 $s = $dbr->getArray( 'cur',
1260 array( 'cur_text' ),
1261 array(
1262 'cur_namespace' => $ns,
1263 'cur_title' => $title,
1264 ), $fname
1265 );
1266
1267 if( $s !== false ) {
1268 # if this is a mini-text, we can paste part of it into the deletion reason
1269
1270 #if this is empty, an earlier revision may contain "useful" text
1271 $blanked = false;
1272 if($s->cur_text!="") {
1273 $text=$s->cur_text;
1274 } else {
1275 if($old) {
1276 $text = Article::getRevisionText( $old );
1277 $blanked = true;
1278 }
1279
1280 }
1281
1282 $length=strlen($text);
1283
1284 # this should not happen, since it is not possible to store an empty, new
1285 # page. Let's insert a standard text in case it does, though
1286 if($length == 0 && $reason === '') {
1287 $reason = wfMsg('exblank');
1288 }
1289
1290 if($length < 500 && $reason === '') {
1291
1292 # comment field=255, let's grep the first 150 to have some user
1293 # space left
1294 $text=substr($text,0,150);
1295 # let's strip out newlines and HTML tags
1296 $text=preg_replace('/\"/',"'",$text);
1297 $text=preg_replace('/\</','&lt;',$text);
1298 $text=preg_replace('/\>/','&gt;',$text);
1299 $text=preg_replace("/[\n\r]/",'',$text);
1300 if(!$blanked) {
1301 $reason=wfMsg('excontent'). " '".$text;
1302 } else {
1303 $reason=wfMsg('exbeforeblank') . " '".$text;
1304 }
1305 if($length>150) { $reason .= '...'; } # we've only pasted part of the text
1306 $reason.="'";
1307 }
1308 }
1309
1310 return $this->confirmDelete( '', $reason );
1311 }
1312
1313 # Output deletion confirmation dialog
1314 function confirmDelete( $par, $reason )
1315 {
1316 global $wgOut;
1317
1318 wfDebug( "Article::confirmDelete\n" );
1319
1320 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1321 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1322 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1323 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1324
1325 $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
1326
1327 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1328 $check = htmlspecialchars( wfMsg( 'confirmcheck' ) );
1329 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1330
1331 $wgOut->addHTML( "
1332 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1333 <table border='0'>
1334 <tr>
1335 <td align='right'>
1336 <label for='wpReason'>{$delcom}:</label>
1337 </td>
1338 <td align='left'>
1339 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1340 </td>
1341 </tr>
1342 <tr>
1343 <td>&nbsp;</td>
1344 </tr>
1345 <tr>
1346 <td align='right'>
1347 <input type='checkbox' name='wpConfirm' value='1' id='wpConfirm' />
1348 </td>
1349 <td>
1350 <label for='wpConfirm'>{$check}</label>
1351 </td>
1352 </tr>
1353 <tr>
1354 <td>&nbsp;</td>
1355 <td>
1356 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1357 </td>
1358 </tr>
1359 </table>
1360 </form>\n" );
1361
1362 $wgOut->returnToMain( false );
1363 }
1364
1365 # Perform a deletion and output success or failure messages
1366 function doDelete( $reason )
1367 {
1368 global $wgOut, $wgUser, $wgLang;
1369 $fname = 'Article::doDelete';
1370 wfDebug( "$fname\n" );
1371
1372 if ( $this->doDeleteArticle( $reason ) ) {
1373 $deleted = $this->mTitle->getPrefixedText();
1374
1375 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1376 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1377
1378 $sk = $wgUser->getSkin();
1379 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
1380 Namespace::getWikipedia() ) .
1381 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
1382
1383 $text = wfMsg( "deletedtext", $deleted, $loglink );
1384
1385 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
1386 $wgOut->returnToMain( false );
1387 } else {
1388 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1389 }
1390 }
1391
1392 # Back-end article deletion
1393 # Deletes the article with database consistency, writes logs, purges caches
1394 # Returns success
1395 function doDeleteArticle( $reason )
1396 {
1397 global $wgUser, $wgLang;
1398 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1399
1400 $fname = 'Article::doDeleteArticle';
1401 wfDebug( $fname."\n" );
1402
1403 $dbw =& wfGetDB( DB_WRITE );
1404 $ns = $this->mTitle->getNamespace();
1405 $t = $this->mTitle->getDBkey();
1406 $id = $this->mTitle->getArticleID();
1407
1408 if ( '' == $t || $id == 0 ) {
1409 return false;
1410 }
1411
1412 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
1413 array_push( $wgDeferredUpdateList, $u );
1414
1415 $linksTo = $this->mTitle->getLinksTo();
1416
1417 # Squid purging
1418 if ( $wgUseSquid ) {
1419 $urls = array(
1420 $this->mTitle->getInternalURL(),
1421 $this->mTitle->getInternalURL( 'history' )
1422 );
1423 foreach ( $linksTo as $linkTo ) {
1424 $urls[] = $linkTo->getInternalURL();
1425 }
1426
1427 $u = new SquidUpdate( $urls );
1428 array_push( $wgDeferredUpdateList, $u );
1429
1430 }
1431
1432 # Client and file cache invalidation
1433 Title::touchArray( $linksTo );
1434
1435 # Move article and history to the "archive" table
1436 $archiveTable = $dbw->tableName( 'archive' );
1437 $oldTable = $dbw->tableName( 'old' );
1438 $curTable = $dbw->tableName( 'cur' );
1439 $recentchangesTable = $dbw->tableName( 'recentchanges' );
1440 $linksTable = $dbw->tableName( 'links' );
1441 $brokenlinksTable = $dbw->tableName( 'brokenlinks' );
1442
1443 $dbw->insertSelect( 'archive', 'cur',
1444 array(
1445 'ar_namespace' => 'cur_namespace',
1446 'ar_title' => 'cur_title',
1447 'ar_text' => 'cur_text',
1448 'ar_comment' => 'cur_comment',
1449 'ar_user' => 'cur_user',
1450 'ar_user_text' => 'cur_user_text',
1451 'ar_timestamp' => 'cur_timestamp',
1452 'ar_minor_edit' => 'cur_minor_edit',
1453 'ar_flags' => 0,
1454 ), array(
1455 'cur_namespace' => $ns,
1456 'cur_title' => $t,
1457 ), $fname
1458 );
1459
1460 $dbw->insertSelect( 'archive', 'old',
1461 array(
1462 'ar_namespace' => 'old_namespace',
1463 'ar_title' => 'old_title',
1464 'ar_text' => 'old_text',
1465 'ar_comment' => 'old_comment',
1466 'ar_user' => 'old_user',
1467 'ar_user_text' => 'old_user_text',
1468 'ar_timestamp' => 'old_timestamp',
1469 'ar_minor_edit' => 'old_minor_edit',
1470 'ar_flags' => 'old_flags'
1471 ), array(
1472 'old_namespace' => $ns,
1473 'old_title' => $t,
1474 ), $fname
1475 );
1476
1477 # Now that it's safely backed up, delete it
1478
1479 $dbw->delete( 'cur', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname );
1480 $dbw->delete( 'old', array( 'old_namespace' => $ns, 'old_title' => $t ), $fname );
1481 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1482
1483 # Finally, clean up the link tables
1484 $t = $this->mTitle->getPrefixedDBkey();
1485
1486 Article::onArticleDelete( $this->mTitle );
1487
1488 # Insert broken links
1489 $brokenLinks = array();
1490 foreach ( $linksTo as $titleObj ) {
1491 # Get article ID. Efficient because it was loaded into the cache by getLinksTo().
1492 $linkID = $titleObj->getArticleID();
1493 $brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t );
1494 }
1495 $dbw->insertArray( 'brokenlinks', $brokenLinks, $fname );
1496
1497 # Delete live links
1498 $dbw->delete( 'links', array( 'l_to' => $id ) );
1499 $dbw->delete( 'links', array( 'l_from' => $id ) );
1500 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1501 $dbw->delete( 'brokenlinks', array( 'bl_from' => $id ) );
1502 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1503
1504 # Log the deletion
1505 $log = new LogPage( wfMsg( 'dellogpage' ), wfMsg( 'dellogpagetext' ) );
1506 $art = $this->mTitle->getPrefixedText();
1507 $log->addEntry( wfMsg( 'deletedarticle', $art ), $reason );
1508
1509 # Clear the cached article id so the interface doesn't act like we exist
1510 $this->mTitle->resetArticleID( 0 );
1511 $this->mTitle->mArticleID = 0;
1512 return true;
1513 }
1514
1515 function rollback()
1516 {
1517 global $wgUser, $wgLang, $wgOut, $wgRequest;
1518 $fname = "Article::rollback";
1519
1520 if ( ! $wgUser->isSysop() ) {
1521 $wgOut->sysopRequired();
1522 return;
1523 }
1524 if ( wfReadOnly() ) {
1525 $wgOut->readOnlyPage( $this->getContent( true ) );
1526 return;
1527 }
1528 $dbw =& wfGetDB( DB_WRITE );
1529
1530 # Enhanced rollback, marks edits rc_bot=1
1531 $bot = $wgRequest->getBool( 'bot' );
1532
1533 # Replace all this user's current edits with the next one down
1534 $tt = $this->mTitle->getDBKey();
1535 $n = $this->mTitle->getNamespace();
1536
1537 # Get the last editor, lock table exclusively
1538 $s = $dbw->getArray( 'cur',
1539 array( 'cur_id','cur_user','cur_user_text','cur_comment' ),
1540 array( 'cur_title' => $tt, 'cur_namespace' => $n ),
1541 $fname, 'FOR UPDATE'
1542 );
1543 if( $s === false ) {
1544 # Something wrong
1545 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1546 return;
1547 }
1548 $ut = $dbw->strencode( $s->cur_user_text );
1549 $uid = $s->cur_user;
1550 $pid = $s->cur_id;
1551
1552 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1553 if( $from != $s->cur_user_text ) {
1554 $wgOut->setPageTitle(wfmsg('rollbackfailed'));
1555 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
1556 htmlspecialchars( $this->mTitle->getPrefixedText()),
1557 htmlspecialchars( $from ),
1558 htmlspecialchars( $s->cur_user_text ) ) );
1559 if($s->cur_comment != '') {
1560 $wgOut->addHTML(
1561 wfMsg('editcomment',
1562 htmlspecialchars( $s->cur_comment ) ) );
1563 }
1564 return;
1565 }
1566
1567 # Get the last edit not by this guy
1568 $s = $dbw->getArray( 'old',
1569 array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
1570 array(
1571 'old_namespace' => $n,
1572 'old_title' => $tt,
1573 "old_user <> {$uid} OR old_user_text <> '{$ut}'"
1574 ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
1575 );
1576 if( $s === false ) {
1577 # Something wrong
1578 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
1579 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
1580 return;
1581 }
1582
1583 if ( $bot ) {
1584 # Mark all reverted edits as bot
1585 $dbw->updateArray( 'recentchanges',
1586 array( /* SET */
1587 'rc_bot' => 1
1588 ), array( /* WHERE */
1589 'rc_user' => $uid,
1590 "rc_timestamp > '{$s->old_timestamp}'",
1591 ), $fname
1592 );
1593 }
1594
1595 # Save it!
1596 $newcomment = wfMsg( 'revertpage', $s->old_user_text, $from );
1597 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1598 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1599 $wgOut->addHTML( '<h2>' . $newcomment . "</h2>\n<hr />\n" );
1600 $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
1601 Article::onArticleEdit( $this->mTitle );
1602 $wgOut->returnToMain( false );
1603 }
1604
1605
1606 # Do standard deferred updates after page view
1607
1608 /* private */ function viewUpdates()
1609 {
1610 global $wgDeferredUpdateList;
1611 if ( 0 != $this->getID() ) {
1612 global $wgDisableCounters;
1613 if( !$wgDisableCounters ) {
1614 Article::incViewCount( $this->getID() );
1615 $u = new SiteStatsUpdate( 1, 0, 0 );
1616 array_push( $wgDeferredUpdateList, $u );
1617 }
1618 $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
1619 $this->mTitle->getDBkey() );
1620 array_push( $wgDeferredUpdateList, $u );
1621 }
1622 }
1623
1624 # Do standard deferred updates after page edit.
1625 # Every 1000th edit, prune the recent changes table.
1626
1627 /* private */ function editUpdates( $text )
1628 {
1629 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1630 global $wgMessageCache;
1631
1632 wfSeedRandom();
1633 if ( 0 == mt_rand( 0, 999 ) ) {
1634 $dbw =& wfGetDB( DB_WRITE );
1635 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1636 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1637 $dbw->query( $sql );
1638 }
1639 $id = $this->getID();
1640 $title = $this->mTitle->getPrefixedDBkey();
1641 $shortTitle = $this->mTitle->getDBkey();
1642
1643 $adj = $this->mCountAdjustment;
1644
1645 if ( 0 != $id ) {
1646 $u = new LinksUpdate( $id, $title );
1647 array_push( $wgDeferredUpdateList, $u );
1648 $u = new SiteStatsUpdate( 0, 1, $adj );
1649 array_push( $wgDeferredUpdateList, $u );
1650 $u = new SearchUpdate( $id, $title, $text );
1651 array_push( $wgDeferredUpdateList, $u );
1652
1653 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
1654 array_push( $wgDeferredUpdateList, $u );
1655
1656 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1657 $wgMessageCache->replace( $shortTitle, $text );
1658 }
1659 }
1660 }
1661
1662 /* private */ function setOldSubtitle()
1663 {
1664 global $wgLang, $wgOut;
1665
1666 $td = $wgLang->timeanddate( $this->mTimestamp, true );
1667 $r = wfMsg( 'revisionasof', $td );
1668 $wgOut->setSubtitle( "({$r})" );
1669 }
1670
1671 # This function is called right before saving the wikitext,
1672 # so we can do things like signatures and links-in-context.
1673
1674 function preSaveTransform( $text )
1675 {
1676 global $wgParser, $wgUser;
1677 return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
1678 }
1679
1680 /* Caching functions */
1681
1682 # checkLastModified returns true if it has taken care of all
1683 # output to the client that is necessary for this request.
1684 # (that is, it has sent a cached version of the page)
1685 function tryFileCache() {
1686 static $called = false;
1687 if( $called ) {
1688 wfDebug( " tryFileCache() -- called twice!?\n" );
1689 return;
1690 }
1691 $called = true;
1692 if($this->isFileCacheable()) {
1693 $touched = $this->mTouched;
1694 if( $this->mTitle->getPrefixedDBkey() == wfMsg( 'mainpage' ) ) {
1695 # Expire the main page quicker
1696 $expire = wfUnix2Timestamp( time() - 3600 );
1697 $touched = max( $expire, $touched );
1698 }
1699 $cache = new CacheManager( $this->mTitle );
1700 if($cache->isFileCacheGood( $touched )) {
1701 global $wgOut;
1702 wfDebug( " tryFileCache() - about to load\n" );
1703 $cache->loadFromFileCache();
1704 return true;
1705 } else {
1706 wfDebug( " tryFileCache() - starting buffer\n" );
1707 ob_start( array(&$cache, 'saveToFileCache' ) );
1708 }
1709 } else {
1710 wfDebug( " tryFileCache() - not cacheable\n" );
1711 }
1712 }
1713
1714 function isFileCacheable() {
1715 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
1716 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
1717
1718 return $wgUseFileCache
1719 and (!$wgShowIPinHeader)
1720 and ($this->getID() != 0)
1721 and ($wgUser->getId() == 0)
1722 and (!$wgUser->getNewtalk())
1723 and ($this->mTitle->getNamespace() != Namespace::getSpecial())
1724 and ($action == 'view')
1725 and (!isset($oldid))
1726 and (!isset($diff))
1727 and (!isset($redirect))
1728 and (!isset($printable))
1729 and (!$this->mRedirectedFrom);
1730 }
1731
1732 # Loads cur_touched and returns a value indicating if it should be used
1733 function checkTouched() {
1734 $id = $this->getID();
1735 $dbr =& wfGetDB( DB_READ );
1736 $s = $dbr->getArray( 'cur', array( 'cur_touched', 'cur_is_redirect' ),
1737 array( 'cur_id' => $id ), $fname );
1738 if( $s !== false ) {
1739 $this->mTouched = $s->cur_touched;
1740 return !$s->cur_is_redirect;
1741 } else {
1742 return false;
1743 }
1744 }
1745
1746 # Edit an article without doing all that other stuff
1747 function quickEdit( $text, $comment = '', $minor = 0 ) {
1748 global $wgUser, $wgMwRedir;
1749 $fname = 'Article::quickEdit';
1750 wfProfileIn( $fname );
1751
1752 $dbw =& wfGetDB( DB_WRITE );
1753 $ns = $this->mTitle->getNamespace();
1754 $dbkey = $this->mTitle->getDBkey();
1755 $encDbKey = $dbw->strencode( $dbkey );
1756 $timestamp = wfTimestampNow();
1757
1758 # Save to history
1759 $dbw->insertSelect( 'old', 'cur',
1760 array(
1761 'old_namespace' => 'cur_namespace',
1762 'old_title' => 'cur_title',
1763 'old_text' => 'cur_text',
1764 'old_comment' => 'cur_comment',
1765 'old_user' => 'cur_user',
1766 'old_user_text' => 'cur_user_text',
1767 'old_timestamp' => 'cur_timestamp',
1768 'inverse_timestamp' => '99999999999999-cur_timestamp',
1769 ), array(
1770 'cur_namespace' => $ns,
1771 'cur_title' => $dbkey,
1772 ), $fname
1773 );
1774
1775 # Use the affected row count to determine if the article is new
1776 $numRows = $dbw->affectedRows();
1777
1778 # Make an array of fields to be inserted
1779 $fields = array(
1780 'cur_text' => $text,
1781 'cur_timestamp' => $timestamp,
1782 'cur_user' => $wgUser->getID(),
1783 'cur_user_text' => $wgUser->getName(),
1784 'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
1785 'cur_comment' => $comment,
1786 'cur_is_redirect' => $wgMwRedir->matchStart( $text ) ? 1 : 0,
1787 'cur_minor_edit' => intval($minor),
1788 'cur_touched' => $timestamp,
1789 );
1790
1791 if ( $numRows ) {
1792 # Update article
1793 $fields['cur_is_new'] = 0;
1794 $dbw->updateArray( 'cur', $fields, array( 'cur_namespace' => $ns, 'cur_title' => $dbkey ), $fname );
1795 } else {
1796 # Insert new article
1797 $fields['cur_is_new'] = 1;
1798 $fields['cur_namespace'] = $ns;
1799 $fields['cur_title'] = $dbkey;
1800 $fields['cur_random'] = $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
1801 $dbw->insertArray( 'cur', $fields, $fname );
1802 }
1803 wfProfileOut( $fname );
1804 }
1805
1806 /* static */ function incViewCount( $id )
1807 {
1808 $id = intval( $id );
1809 global $wgHitcounterUpdateFreq;
1810
1811 $dbw =& wfGetDB( DB_WRITE );
1812 $curTable = $dbw->tableName( 'cur' );
1813 $hitcounterTable = $dbw->tableName( 'hitcounter' );
1814 $acchitsTable = $dbw->tableName( 'acchits' );
1815
1816 if( $wgHitcounterUpdateFreq <= 1 ){ //
1817 $dbw->query( "UPDATE $curTable SET cur_counter = cur_counter + 1 WHERE cur_id = $id" );
1818 return;
1819 }
1820
1821 # Not important enough to warrant an error page in case of failure
1822 $oldignore = $dbw->setIgnoreErrors( true );
1823
1824 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
1825
1826 $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
1827 if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
1828 # Most of the time (or on SQL errors), skip row count check
1829 $dbw->setIgnoreErrors( $oldignore );
1830 return;
1831 }
1832
1833 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
1834 $row = $dbw->fetchObject( $res );
1835 $rown = intval( $row->n );
1836 if( $rown >= $wgHitcounterUpdateFreq ){
1837 wfProfileIn( 'Article::incViewCount-collect' );
1838 $old_user_abort = ignore_user_abort( true );
1839
1840 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
1841 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
1842 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
1843 'GROUP BY hc_id');
1844 $dbw->query("DELETE FROM $hitcounterTable");
1845 $dbw->query('UNLOCK TABLES');
1846 $dbw->query("UPDATE $curTable,$acchitsTable SET cur_counter=cur_counter + hc_n ".
1847 'WHERE cur_id = hc_id');
1848 $dbw->query("DROP TABLE $acchitsTable");
1849
1850 ignore_user_abort( $old_user_abort );
1851 wfProfileOut( 'Article::incViewCount-collect' );
1852 }
1853 $dbw->setIgnoreErrors( $oldignore );
1854 }
1855
1856 # The onArticle*() functions are supposed to be a kind of hooks
1857 # which should be called whenever any of the specified actions
1858 # are done.
1859 #
1860 # This is a good place to put code to clear caches, for instance.
1861
1862 # This is called on page move and undelete, as well as edit
1863 /* static */ function onArticleCreate($title_obj){
1864 global $wgUseSquid, $wgDeferredUpdateList;
1865
1866 $titles = $title_obj->getBrokenLinksTo();
1867
1868 # Purge squid
1869 if ( $wgUseSquid ) {
1870 $urls = $title_obj->getSquidURLs();
1871 foreach ( $titles as $linkTitle ) {
1872 $urls[] = $linkTitle->getInternalURL();
1873 }
1874 $u = new SquidUpdate( $urls );
1875 array_push( $wgDeferredUpdateList, $u );
1876 }
1877
1878 # Clear persistent link cache
1879 LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
1880 }
1881
1882 /* static */ function onArticleDelete($title_obj){
1883 LinkCache::linksccClearLinksTo( $title_obj->getArticleID() );
1884 }
1885
1886 /* static */ function onArticleEdit($title_obj){
1887 LinkCache::linksccClearPage( $title_obj->getArticleID() );
1888 }
1889
1890 # Info about this page
1891
1892 function info()
1893 {
1894 global $wgUser, $wgTitle, $wgOut, $wgLang, $wgAllowPageInfo;
1895
1896 if ( !$wgAllowPageInfo ) {
1897 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
1898 return;
1899 }
1900
1901 $basenamespace = $wgTitle->getNamespace() & (~1);
1902 $cur_clause = "cur_title='".$wgTitle->getDBkey()."' AND cur_namespace=".$basenamespace;
1903 $old_clause = "old_title='".$wgTitle->getDBkey()."' AND old_namespace=".$basenamespace;
1904 $wl_clause = "wl_title='".$wgTitle->getDBkey()."' AND wl_namespace=".$basenamespace;
1905 $fullTitle = $wgTitle->makeName($basenamespace, $wgTitle->getDBKey());
1906 $wgOut->setPagetitle( $fullTitle );
1907 $wgOut->setSubtitle( wfMsg( "infosubtitle" ));
1908
1909 # first, see if the page exists at all.
1910 $sql = "SELECT COUNT(*) FROM cur WHERE ".$cur_clause;
1911 $exists = wfSingleQuery( $sql , DB_READ );
1912 if ($exists < 1) {
1913 $wgOut->addHTML( wfMsg("noarticletext") );
1914 } else {
1915 $sql = "SELECT COUNT(*) FROM watchlist WHERE ".$wl_clause;
1916 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers") . wfSingleQuery( $sql, DB_READ ) . "</li>" );
1917 $sql = "SELECT COUNT(*) FROM old WHERE ".$old_clause;
1918 $old = wfSingleQuery( $sql, DB_READ );
1919 $wgOut->addHTML( "<li>" . wfMsg("numedits") . ($old + 1) . "</li>");
1920
1921 # to find number of distinct authors, we need to do some
1922 # funny stuff because of the cur/old table split:
1923 # - first, find the name of the 'cur' author
1924 # - then, find the number of *other* authors in 'old'
1925
1926 # find 'cur' author
1927 $sql = "SELECT cur_user_text FROM cur WHERE ".$cur_clause;
1928 $cur_author = wfSingleQuery( $sql, DB_READ );
1929
1930 # find number of 'old' authors excluding 'cur' author
1931 $sql = "SELECT COUNT(DISTINCT old_user_text) FROM old WHERE ".$old_clause
1932 ." AND old_user_text<>'" . $cur_author . "'";
1933 $authors = wfSingleQuery( $sql, DB_READ ) + 1;
1934
1935 # now for the Talk page ...
1936 $cur_clause = "cur_title='".$wgTitle->getDBkey()."' AND cur_namespace=".($basenamespace+1);
1937 $old_clause = "old_title='".$wgTitle->getDBkey()."' AND old_namespace=".($basenamespace+1);
1938
1939 # does it exist?
1940 $sql = "SELECT COUNT(*) FROM cur WHERE ".$cur_clause;
1941 $exists = wfSingleQuery( $sql , DB_READ );
1942
1943 # number of edits
1944 if ($exists > 0) {
1945 $sql = "SELECT COUNT(*) FROM old WHERE ".$old_clause;
1946 $old = wfSingleQuery( $sql, DB_READ );
1947 $wgOut->addHTML( "<li>" . wfMsg("numtalkedits") . ($old + 1) . "</li>");
1948 }
1949 $wgOut->addHTML( "<li>" . wfMsg("numauthors") . $authors . "</li>" );
1950
1951 # number of authors
1952 if ($exists > 0) {
1953 $sql = "SELECT cur_user_text FROM cur WHERE ".$cur_clause;
1954 $cur_author = wfSingleQuery( $sql, DB_READ );
1955
1956 $sql = "SELECT COUNT(DISTINCT old_user_text) FROM old WHERE "
1957 .$old_clause." AND old_user_text<>'" . $cur_author . "'";
1958 $authors = wfSingleQuery( $sql, DB_READ ) + 1;
1959
1960 $wgOut->addHTML( "<li>" . wfMsg("numtalkauthors") . $authors . "</li></ul>" );
1961 }
1962 }
1963 }
1964 }
1965
1966 ?>